<?php
namespace common\logic\hprose;

use yii\db\Exception;

/**
 * Class Substance
 * @package common\logic\hprose
 *
 * @author  syy
 * @date    2021-12-14 下午3:12
 */
class ServiceFactory
{
    /**
     * 服务工厂
     * @var
     */
    private static $obj;

    // 不能被 new 出来
    private function __construct(){
    
    }
    
    /**
     * @param       $type
     * @param array $config
     *
     * @return null
     * @throws \Exception
     */
    public static function GetService($type)
    {
        try{
            switch ($type){
                case 'project':
                    self::$obj = new project\ProjectService();
                    break;
                case 'user':
                    self::$obj = new user\UserService();
                    break;
                default:
                    throw new Exception('Service does not exist');
            }
            return self::$obj;
        }catch (Exception $exception){
            throw new \Exception($exception->getMessage());
            exit;
        }
        
    }
}